package com.jsmile.cloud.msgcenter.web.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.jsmile.cloud.msgcenter.api.constants.MsgConstants;
import com.jsmile.cloud.promotioncenter.api.constants.PromotionConstants;
import com.jsmile.cloud.tradecenter.api.constants.TradeConstants;

import lombok.extern.slf4j.Slf4j;

/**
 * rabbitmq消息配置
 *
 * @author 亮亮
 * @version 1.0.0
 * @date 2017年3月30日 下午3:34:16
 */
@Configuration
@Slf4j
public class RabbitmqConfig {

    /*********************** 短信发送 ***************************/
    @Bean
    public Queue smsDirectQueue() {
        return new Queue(MsgConstants.SmsMq.SMS_SEND_QUEUE, true); // true 是否持久
    }

    @Bean
    DirectExchange smsDirectExchange() {
        return new DirectExchange(MsgConstants.SmsMq.SMS_SEND_EXCHANGE);
    }

    @Bean
    Binding bindingSmsDirect() {
        return BindingBuilder.bind(smsDirectQueue()).to(smsDirectExchange()).with(MsgConstants.SmsMq.SMS_SEND_ROUTE);
    }

    /*********************** 订单状态变化 ***************************/
    @Bean
    public Queue orderDirectQueue() {
        return new Queue(TradeConstants.TradeMq.MSG_ORDER_STATUS_SYNC_QUEUE, true); // true 是否持久
    }

    @Bean
    DirectExchange orderDirectExchange() {
        return new DirectExchange(TradeConstants.TradeMq.MSG_ORDER_STATUS_SYNC_EXCHANGE);
    }

    @Bean
    Binding bindingOrderDirect() {
        return BindingBuilder.bind(orderDirectQueue()).to(orderDirectExchange()).with(TradeConstants.TradeMq.MSG_ORDER_STATUS_SYNC_ROUTE);
    }

    /*********************** 拼团状态变化 ***************************/
    @Bean
    public Queue groupDirectQueue() {
        return new Queue(PromotionConstants.PromotionMq.MSG_GROUP_STATUS_SYNC_QUEUE, true); // true 是否持久
    }

    @Bean
    DirectExchange groupDirectExchange() {
        return new DirectExchange(PromotionConstants.PromotionMq.MSG_GROUP_STATUS_SYNC_EXCHANGE);
    }

    @Bean
    Binding bindingGroupDirect() {
        return BindingBuilder.bind(groupDirectQueue()).to(groupDirectExchange()).with(PromotionConstants.PromotionMq.MSG_GROUP_STATUS_SYNC_ROUTE);
    }
}
